package com.nbgs.demo.controller;

import com.nbgs.demo.common.Result;
import com.nbgs.demo.controller.info.Form;
import com.nbgs.demo.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@CrossOrigin("*")
@RestController
@Slf4j
public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping(value = "/login")
    public Result login(@RequestBody Form form, HttpSession httpSession){
        httpSession.setAttribute("cardNum",form.getCardNum());
        log.info("登陆操作{}",form,httpSession);
        if (loginService.login(form,httpSession)!=null){
            return Result.success(form);
        }else {
            return Result.fail("登录失败，用户名或者密码不正确");
        }
    }
}
